<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/19
 * Time: 11:04
 */

namespace app\admin\controller;
use app\common\model\HuiYuanSupervise;
class Mobile extends Base{
    protected static $arr = array();
    
    public function _initialize(){
        parent::_initialize();
        $this->member_model= new HuiYuanSupervise();
       
    }

    public function advert(){
        $files = self::findFile("uploads/advice");
        $list = array();
        foreach($files as $v){
            $list[base64_encode($v)] = $v;
        }
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function addAdvert(){

        $file_name = request()->file('file');
        $info = $file_name->move(ROOT_PATH . 'public/uploads/advice',time());
        if($info){
            $this->member_model->caozuorizhi_xieru('添加了一条新APP广告');
            js_tishi('添加成功', '/admin/Mobile/advert');
        }else{
            js_tishi('添加失败', '/admin/Mobile/advert');
        }
    }
    public function delAdvice(){
        $file = input('post.file');
        $file = base64_decode($file);
        if (!unlink(ROOT_PATH.'public/'.$file)){
            return json(array('code'=>0));
        }else{
            $this->member_model->caozuorizhi_xieru('删除了一条APP新广告');
            return json(array('code'=>1));
        }
    }
    static function findFile($flodername){
        if ( is_dir($flodername) && $fd = opendir($flodername)) {
            while($file = readdir($fd)) {
                if ($file != "." && $file != "..") {
                    $newPath = $flodername.'/'.$file;
                    if (is_dir($newPath)) {
                        self::findFile($newPath);
                    } else {
                        self::$arr[$file] = $newPath;
                    }
                }
            }
        }
        return self::$arr;
    }
}